package com.vdf.sisconsolid.rest.definition;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import com.vdf.sisconsolid.rest.RestBase;
import com.vdf.sisconsolid.rest.type.Position;

@Path("positions")
public class RestPosition extends RestBase {

	static Map responsePosition;
	static int countId = 3;
	static List<Position> pstList = new ArrayList<Position>();
	static {
		responsePosition = new HashMap();
		
		Position cl = new Position();
		cl.setId(1L);
		cl.setLongName("Long Name1");
		cl.setShortName("Short Name1");
		cl.setCreatedDate(new Date());
		cl.setActive(true);
		pstList.add(cl);
		Position cl2 = new Position();
		cl2.setId(2L);
		cl2.setLongName("Long Name2");
		cl2.setShortName("Short Name2");
		cl2.setCreatedDate(new Date());
		cl2.setActive(true);
		pstList.add(cl2);
		
	}

	@GET
	@Produces("application/json")
	public Map<String, Object> get() {
		return super.getResponseRest(true,"Data Loaded", pstList, pstList.size());
	}

	@POST
	@Produces("application/json")
	public Map<String, Object> post(Position position) {
		position.setId((long)countId++);
		pstList.add(position);
		return super.getResponseRest(true,"Data Loaded", position);
	}

	@PUT
	@Path("{id}")
	@Produces("application/json")
	public void put(@PathParam("id")long id, Position position) {
		pstList.set(pstList.indexOf(position), position);

	}

	@DELETE
	@Path("{id}")
	@Produces("application/json")
	public void delete(@PathParam("id") long id) {
		Position cl = new Position();
		cl.setId(id);
		pstList.remove(pstList.indexOf(cl));
	}
	
}
